<template>
  <BaseMainSlot :show-tab="true">
    <template v-slot:search-box>
      <SearchForm :formConfig="formConfig" :formData="searchlist" @search="search"></SearchForm>
    </template>
    <template v-slot:btn-box>
      <ActionBar
        :page-no="76"
        :add-active="forderStatus === 0"
        :del-active="delActive"
        :has-edit="false"
        :has-save="false"
        :has-cancel="false"
        @add="add"
        @del="del"
      />
    </template>
    <template v-slot:tab-select>
      <selectbutton
        :buttonselectlist="forderStatusList"
        @nowselectbuttonindex="nowselectbuttonindex"
      />
    </template>
    <template v-slot:table-box>
      <Table @sortChange="changeTableSort" :propList="tableColumn" v-loading="loading"
        :listData="tableData" @handleSelectionChange="handleSelectionChange">
        <template v-slot:operation="{ row }">
          <template v-if="!row.index">
            <el-button
              v-if="judgePermission(76, 'edit') && forderStatus === 0"
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="edit(row,'auditing')"
            >
              <i class="el-icon-edit-outline"></i> 审核
            </el-button>
            <el-button
              v-if="judgePermission(76, 'edit') && forderStatus === 0"
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="edit(row,'reject') "
            >
              <i class="el-icon-edit-outline"></i> 驳回
            </el-button>
           <!--  <el-button
              v-if="judgePermission(76, 'delete') && forderStatus === 0"
              class="text-btn-cursor cursor-delete"
              type="text"
              size="small"
              @click="handleDelete(row.outboundOrderNo)"
            >
              <i class="el-icon-delete"></i> 删除
            </el-button> -->
            <el-button
              v-if="judgePermission(76, 'edit') && forderStatus ==1"
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="edit(row,'check')"
            >
              <i class="el-icon-view"></i>查看详情
            </el-button>
            <el-button
              v-if="judgePermission(76, 'edit') && forderStatus == 2"
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="edit(row,'reject')"
            >
              <i class="el-icon-view"></i>驳回原因
            </el-button>
          </template>
        </template>
        <template v-slot:materialInfo="{ row }">
          <template v-if="!row.index">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="edit(row,'material')"
            >
              <i class="el-icon-view"></i>查看详情
            </el-button>

          </template>
        </template>
        <template v-slot:outboundOrderType="{ row, item }">
          <template v-if="!row.index">
            {{ getType(row[item.prop]) }}
          </template>
        </template>
        <template v-slot:shouldSendNum="{ row }">
          <template v-if="!row.index">
            {{ row.shouldSendNum }} {{ row.castUnit.symbol || row.castUnit.unitName }}
          </template>
        </template>
        <template v-slot:confirmQuantity="{ row }">
          <template v-if="!row.index">
            {{ row.confirmQuantity }} {{ row.castUnit.symbol || row.castUnit.unitName }}
          </template>
        </template>
        <template v-slot:primaryQuantity="{ row }">
          <template v-if="!row.index">
            {{ row.primaryQuantity }} {{ row.unit.symbol || row.unit.unitName }}
          </template>
        </template>
      </Table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
    <template v-slot:dialog>
      <el-dialog
        :title="titleText"
        :visible.sync="dialogFormVisible"
        @close="cancel('formData')"
      >
      <div v-if="nowChanceStau==='reject' ">
          <div class="input-row" style="display: flex; align-items: center; margin-top: 20px;">
          <label for="rejectReason" style="margin-right: 10px;">驳回原因：</label>
          <el-input
            id="rejectReason"
            type="textarea"
            v-model="formData.reason"
            rows="4"
            :disabled="forderStatus===2"
            style="flex: 1;">
          </el-input>
        </div>
        </div>
        <el-form
          ref="formData"
          label-position="left"
          :model="formData"
          :rules="rules"
          class="el-form"
          v-if="nowChanceStau!=='reject'"
        >
          <el-form-item
            v-if="nowChanceStau === 'add' || nowChanceStau==='check' || nowChanceStau==='auditing'"
            label="出库形式 :"
            class="w100p"
          >
            <el-button v-if="outboundOrderType === 0 || nowChanceStau === 'add'" :type="outboundOrderType === 0 ? 'primary' : ''"     :disabled="nowChanceStau === 'auditing'|| nowChanceStau === 'check'"@click="changeAddWays(0)">销售出库</el-button>
            <el-button v-if="outboundOrderType === 1 || nowChanceStau === 'add'" :type="outboundOrderType === 1 ? 'primary' : ''" :disabled="nowChanceStau === 'auditing'|| nowChanceStau === 'check'"  @click="changeAddWays(1)">自行出库</el-button>
            <el-button v-if="![0, 1].includes(outboundOrderType)"
              :type="![0, 1].includes(outboundOrderType) ? 'primary' : ''"
              :disabled="['check', 'auditing'].includes(nowChanceStau)">{{ getType(outboundOrderType) }}</el-button>
          </el-form-item>
          <el-form-item
            v-if="outboundOrderType === 0 && nowChanceStau === 'add'"
            label="源头单据类型 :"
            prop="sourceDocType"
            class="w50p"
            :rules="[{required: true,message:'源头单据类型不能为空',trigger:'change'}]"
          >
            <el-select
              v-model="formData.sourceDocType"
              placeholder="请选择源头单据类型"
              clearable
            >
              <el-option
                v-for="items,indexs in sourceDocTypeList"
                :key="indexs"
                :label="items.name"
                :value="items.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item
            v-if="outboundOrderType === 0 && nowChanceStau === 'add'"
            label="源头单号 :"
            prop="sourceDocNo"
            class="w50p"
            :rules="[{required: true,message:'源头单明细号不能为空',trigger:'change'}]"
          >
            <el-select
              v-model="formData.sourceDocNo"
              placeholder="请选择源头单号"
              clearable
              @change="getOrderDetailList"
            >
              <el-option
                v-for="items,indexs in sourceDocNoList"
                :key="indexs"
                :label="items.saleOrderNo"
                :value="items.saleOrderNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item
            v-if="nowChanceStau === 'add' && outboundOrderType === 0"
            label="选择出库商品 :"
            class="w100p"
          >
            <el-checkbox-group
              v-model="formData.outGoodsList"
              @change="chooseGoods"
            >
              <el-checkbox
                v-for="items,indexs in outGoodsList"
                :key="indexs"
                :label="items"
              >{{ items.materialName }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item
              label="出库单号："
              v-if="nowChanceStau!=='add'"
              class="w50p"
              prop="outboundOrderNo"
              :rules="[{required: true, message: '入库单号不能为空', trigger: 'change'}]"
            >
              <el-input
                clearable
                v-model="formData.outboundOrderNo"
                placeholder="请输入入库单号"
                disabled
              />
            </el-form-item>
            <el-form-item
              label="出库日期 :"
              v-if="nowChanceStau==='check'|| nowChanceStau==='auditing' "
              prop="outTime"
              class="w50p"
              :rules="[{required: true,message:'出货不能为空',trigger:'change'}]"
            >
              <el-date-picker
                v-model="formData.outTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm"
                clearable
                :disabled="nowChanceStau === 'check'"
                placeholder="请选择时间"
              />
            </el-form-item>
            <template>
              <div
                v-for="orderDetail,index in formData.putInStorageList"
                :key="orderDetail.key"
                class="w100p xunhuan"
                :class="{ 'first': index == 0 }"
              >
                <div class="goods">出库货{{ index + 1 }}</div>
                <el-form-item
                  label="出库货名 :"
                  :prop="'putInStorageList.' + index + '.materialNo'"
                  class="w50p"
                  :rules="[{required: true,message:'出库货名不能为空',trigger:'change'}]"
                >
                  <el-select
                    v-model="orderDetail.materialNo"
                    placeholder="请选择出库货名称"
                    clearable
                    filterable
                    :disabled="outboundOrderType === 0 || nowChanceStau === 'check' || nowChanceStau==='material' || nowChanceStau==='auditing'"
                    @change="getGoods($event,index)"
                  >
                    <el-option
                      v-for="items,indexs in materialList"
                      :key="indexs"
                      :label="items.materialName"
                      :value="items.materialNo"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item
                  label="行号 :"
                  :prop="'putInStorageList.' + index + '.inenumber'"
                  class="w50p"
                  v-if="outboundOrderType != 0"
                  >
                  <el-input
                  clearable
                  :value="index+1"
                  placeholder="行号"
                  :disabled="true"
              />
                </el-form-item>
                <el-form-item
                  v-if="(outboundOrderType === 0 && nowChanceStau==='add') || ['material', 'auditing'].includes(nowChanceStau)"
                  label="应出数量 :"
                  :prop="'putInStorageList.' + index + '.shouldSendNum'"
                  class="w50p"
                  :rules="[{pattern: /^([1-9]\d*(\.\d*[1-9][0-9])?)|(0\.\d*[1-9][0-9])|(0\.\d*[1-9])$/,message:'值该为大于0的数',trigger: ['change','blur']},
                          {required: true,message:'数量不能为空',trigger:'change'}]"
                >
                  <el-input
                    v-model="orderDetail.shouldSendNum"
                    clearable
                    disabled
                    placeholder="请输入应出数量"
                  />
                </el-form-item>
                <div
                  class="line-box"
                  v-for="lineDetail,i in orderDetail.lineList"
                  :key="index + i"
                  :class="{ 'margin': i == orderDetail.lineList.length - 1 }"
                >
                  <el-form-item
                    v-if="outboundOrderType !== 0 && nowChanceStau !== 'material'"
                    label="选择货品批次:"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.batchObj'"
                    class="w100p"
                  >
                    <el-select
                      v-model="lineDetail.batchObj"
                      placeholder="点击选择"
                      filterable
                      clearable
                      value-key="onHandQuantityId"
                      :disabled="nowChanceStau==='check'"
                      @change="batchObjChange($event, index, i)"
                    >
                      <el-option
                        v-for="item in orderDetail.batchList"
                        :key="item.onHandQuantityId"
                        :label="'批号: ' + (item.batchFile ? item.batchFile.lotNumber || '-' : '-') + ',  该批次现存主数量 : ' + item.onHandQuantity+ (item.cUnit.symbol || item.cUnit.unitName ) + ',  生产日期 : ' + (item.batchFile ? item.batchFile.produceDate || '-' : '-')+ ',  失效日期 : ' + (item.batchFile ? item.batchFile.expirationDate || '-' : '-')"
                        :value="item"
                      />
                    </el-select>

                  </el-form-item>
                  <el-form-item
                    label="出货仓库 :"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.stordocNo'"
                    class="w50p"
                    :rules="[{required: true,message:'出货仓库不能为空',trigger:'change'}]"
                  >
                    <el-select
                      v-model="lineDetail.stordocNo"
                      placeholder="请选择出货仓库"
                      clearable
                      @change="formDataChange"
                      :disabled="nowChanceStau==='check' || nowChanceStau==='material' "
                    >
                      <el-option
                        v-for="items,indexs in stordocList"
                        :key="indexs"
                        :label="items.stordocName"
                        :value="items.stordocNo"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item
                    label="单价/元 :"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.price'"
                    class="w50p"
                    v-if="outboundOrderType === 0"
                    :rules="[{pattern: /^[1-9]*[1-9][0-9]*$/,message:'值该大于0',trigger: ['change','blur']}]"
                  >
                    <el-input
                      v-model="lineDetail.price"
                      clearable
                      placeholder="请输入单价"
                      :disabled="nowChanceStau==='material' || nowChanceStau=='check'"
                      @input="formDataChange"
                    />
                  </el-form-item>
                  <el-form-item
                    label="总金额/元 :"
                    v-if="outboundOrderType === 0"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.totalPrice'"
                    class="w50p"
                    :rules="[{pattern: /^[1-9]*[1-9][0-9]*$/,message:'值该大于0',trigger: ['change','blur']}]"
                  >
                    <el-input
                      v-model="lineDetail.totalPrice"
                      clearable
                      placeholder="请输入金额"
                      :disabled="nowChanceStau==='check' || nowChanceStau==='material'"
                      @input="formDataChange"
                    />
                  </el-form-item>
                  <el-form-item
                  v-if="outboundOrderType !== 0 && ['auditing', 'material', 'check'].includes(nowChanceStau)"
                    label="生产日期 :"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.produceDate'"
                    class="w50p"
                    :rules="[{required: true,message:'生产日期不能为空',trigger:'change'}]"
                  >
                    <el-date-picker
                      v-model="lineDetail.produceDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      disabled
                      clearable
                      placeholder="请选择时间"
                    />
                  </el-form-item>
                  <el-form-item
                    v-if="outboundOrderType !== 0 && ['auditing', 'material', 'check'].includes(nowChanceStau)"
                    label="失效日期 :"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.expirationDate'"
                    class="w50p"
                    :rules="[{required: true,message:'失效日期不能为空',trigger:'change'}]"
                  >
                    <el-date-picker
                      v-model="lineDetail.expirationDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      clearable
                      disabled
                      placeholder="请选择时间"
                      @change="getCount($event,index)"
                    />
                  </el-form-item>
                  <el-form-item
                    label="出库日期 :"
                    v-if="nowChanceStau==='check' || nowChanceStau==='add'"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.outTime'"
                    class="w50p"
                    :rules="[{required: true,message:'出货不能为空',trigger:'change'}]"
                  >
                    <el-date-picker
                      v-model="lineDetail.outTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm"
                      clearable
                      :disabled="nowChanceStau === 'check'"
                      placeholder="请选择时间"
                      @change="formDataChange"
                    />
                  </el-form-item>
                  <el-form-item
                    v-if="outboundOrderType === 1"
                    label="现存主数量 :"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.nowQuantity'"
                    class="w50p numberUnit"
                    :rules="[{required: true,message:'数量不能为空',trigger:'blur'},
                            {pattern: /^\d+$/,message:'值该为正整数',trigger: ['change','blur']}]"
                  >
                    <el-input
                      v-model="lineDetail.nowQuantity"
                      clearable
                      disabled
                      class="one"
                      placeholder="现存主数量"
                    />
                    <el-select
                      v-model="lineDetail.unitNo"
                      placeholder="单位"
                      disabled
                      clearable
                      class="two"
                    >
                      <el-option
                        v-for="items,indexs in unitList"
                        :key="indexs"
                        :label="items.symbol || items.unitName"
                        :value="items.unitNo"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item
                    :label="outboundOrderType === 0 ? '实出数量 :' : '出货数量 :'"
                    v-if="nowChanceStau!=='material' "
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.confirmQuantity'"
                    class="w50p numberUnit"
                    :rules="[{required: true,message:'数量不能为空',trigger:'blur'},{pattern: /^([1-9]\d*(\.\d*[1-9][0-9])?)|(0\.\d*[1-9][0-9])|(0\.\d*[1-9])$/,message:'值该为大于0的数',trigger: ['blur','change']},
                    ]"
                  >
                    <el-input
                      v-model="lineDetail.confirmQuantity"
                      clearable
                      class="one"
                      placeholder="请输入数量"
                      :disabled="nowChanceStau === 'check' "
                      @input="getMainQuantity($event, index, i)"
                    />
                    <el-select
                      v-model="lineDetail.castUnitNo"
                      placeholder="单位"
                      clearable
                      class="two"
                      disabled
                    >
                      <el-option
                        v-for="items,indexs in unitList"
                        :key="indexs"
                        :label="items.symbol || items.unitName"
                        :value="items.unitNo"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item
                    label="单位 :"
                    v-if="nowChanceStau!=='material'"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.castUnitNo'"
                    class="w50p"
                    :rules="[{required: true,message:'单位不能为空',trigger:'change'}]"
                  >
                    <el-select
                      v-model="lineDetail.castUnitNo"
                      placeholder="请选择单位"
                      clearable
                      @change="formDataChange"
                      :disabled="outboundOrderType === 0 || nowChanceStau==='material' || nowChanceStau==='check'"
                    >
                      <el-option
                        v-for="items,indexs in unitList"
                        :key="indexs"
                        :label="items.symbol || items.unitName"
                        :value="items.unitNo"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item
                    label="换算率 :"
                    :prop="'putInStorageList.' + index + '.lineList.' + i + '.exchangeRate'"
                    class="w50p"
                    :rules="[{pattern: /^\d+$/,message:'值该为正整数',trigger: ['change','blur']},
                            {required: true,message:'换算率不能为空',trigger:'change'}]"
                  >
                    <el-input
                      v-model="lineDetail.exchangeRate"
                      clearable
                      :disabled="outboundOrderType === 0 || nowChanceStau==='check' || nowChanceStau==='material'"
                      placeholder="请输入换算率"
                      @input="formDataChange"
                    />
                  </el-form-item>
                  <div class="zhu w50p">
                    <el-form-item
                      label="主数量&主单位:"
                      :prop="'putInStorageList.' + index + '.lineList.' + i  + '.primaryQuantity'"
                      style="width: 82%;"
                      :rules="[{pattern: /^([1-9]\d*(\.\d*[1-9][0-9])?)|(0\.\d*[1-9][0-9])|(0\.\d*[1-9])$/,message:'值该为大于0的数',trigger: ['change','blur']},
                              {required: true,message:'数量不能为空',trigger:'change'}]"
                    >
                      <el-input
                        v-model="lineDetail.primaryQuantity"
                        clearable
                        disabled
                        placeholder="请输入主数量"
                      />
                    </el-form-item>
                    <el-form-item
                      :prop="'putInStorageList.' + index + '.lineList.' + i  + '.unitNo'"
                      style="width: 18%;"
                      :rules="[{required: true,message:'主单位不能为空',trigger:'change'}]"
                    >
                      <el-select
                        v-model="lineDetail.unitNo"
                        placeholder="主单位"
                        disabled
                        clearable
                      >
                        <el-option
                          v-for="items,indexs in unitList"
                          :key="indexs"
                          :label="items.symbol || items.unitName"
                          :value="items.unitNo"
                        />
                      </el-select>
                    </el-form-item>
                  </div>
                  <div
                    v-if="['auditing'].includes(nowChanceStau) && outboundOrderType != 0"
                    class="editBox delBox"
                  >
                    <el-button type="info" circle @click="delLineDetail(index, i)">
                      <i class="el-icon-minus"></i>
                    </el-button>
                  </div>
                </div>
                <div class="block">
                  <el-button
                    v-if="['auditing'].includes(nowChanceStau) && outboundOrderType != 0"
                    class="addone"
                    type="info"
                    circle
                    @click="addLineDetail(index)"
                  >
                    <i class="el-icon-plus"></i>
                  </el-button>
                </div>
                <div
                  v-if="['add'].includes(nowChanceStau) && outboundOrderType != 0"
                  class="editBox"
                >
                  <el-button type="info" circle @click="delOrderDetail(index)">
                    <i class="el-icon-minus"></i>
                  </el-button>
                </div>
              </div>
            </template>
          <div v-if="['add'].includes(nowChanceStau) && outboundOrderType != 0">
            <el-button
              class="addone"
              type="info"
              circle
              @click="addOrderDetail"
            >
              <i class="el-icon-plus"></i>
            </el-button>
          </div>
        </el-form>
        <div v-if="nowChanceStau !== ''" slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="cancel('formData')">取 消</el-button>
          <el-button
          v-if="forderStatus === 0 && nowChanceStau!=='reject' && nowChanceStau!=='material'"
          class="zh-button-two" type="primary"
          @click="save('formData')">
          {{ nowChanceStau === 'add' ? '保 存' : '确认出库' }}
        </el-button>
          <el-button v-if="nowChanceStau === 'reject'" class="zh-button-two" type="primary" @click="confirm('formData')">确 定</el-button>
        </div>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>

<script src="">
import SearchForm from '@/components/searchForm';
import Table from '@/components/table/table.vue';
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot";
import selectbutton from "@/components/selectbutton/index.vue";
import { mymixin } from "@/utils/mixins";
import unitApi from "@/api/basic-info-manage/unit-manage"; // 单位
import materialApi from "@/api/basic-info-manage/agr-source-base-Manage"; // 物料
import saleOrderApi from "@/api/livestock-manage/sale-manage/sale-order"; // 销售订单
import saleOrderDetailApi from "@/api/livestock-manage/sale-manage/sale-order-detail"; // 销售订单明细
import warehouseApi from "@/api/livestock-manage/storage-manage/warehouse-manage"; // 仓库
import personApi from "@/api/livestock-manage/personnel-cost-mansge/staff-manage"; // 人员
import deliveryDetailApi from "@/api/livestock-manage/sale-manage/delivery-detail"; // 出货明细
import outStorage from "@/api/livestock-manage/sale-manage/out-storage"; // 出库
import handQuantityApi from "@/api/livestock-manage/storage-manage/quantity-on-hand"; // 现存量
import nowpagereqquery from "@/api/digital-production/production-batch-manage/create-production-batch/index";
import { mapGetters } from "vuex";
export default {
  name: "SheepInformation",
  components: {
    SearchForm,
    Table,
    ActionBar,
    Pagination,
    BaseMainSlot,
    selectbutton
  },
  mixins: [mymixin],
  data() {
    return {
      searchlist: {},
      tableColumn: [],
      formConfig: [
      {
          label: '出库单号',
          prop: 'outboundOrderNo',
          type: 'input',
        },
        {
          label: '出库形式',
          prop: 'outboundOrderType',
          type: 'select',
          options: [
            { name: "销售出库", value: 0 },
            { name: "自行出库", value: 1 }
          ],
          optionKey: { label: 'name', value: 'value' },
        },

        {
          label: '日期选择',
          prop: 'outTime',
          type: 'daterange',
        },
      ],
      forderStatus: 0,
      batchList: [],
      toAdd: {},
      batchNo:'',
      outboundOrderType: 0,
      outGoodsList: [],
      selectedStaffList: [],
      personList: [],
      unitList: [],
      stordocList: [], // 仓库
      putInorderList: [], // 出库单号
      materialList: [], // 货名
      batchNoList: [], // 批次号
      warehousingTypeList: [
        { name: "成品", value: "成品" },
        { name: "半成品", value: "半成品" },
        { name: "原材料", value: "原材料" }
      ], // 出库类型
      sourceDocTypeList: [
        { name: "采购", value: "采购" },
        { name: "销售", value: "销售" }
      ],
      sourceDocNoList: [], // 所有采购订单号
      associatedDocumentTypeList: [
        { name: "采购明细", value: "采购明细" },
        { name: "销售明细", value: "销售明细" }
      ],
      associatedDocumentNoList: [], // 单个订单所有明细
      forderStatusList: [
        { name: "未审核", value: 0 },
        { name: "审核通过", value: 1 },
        { name: "审核未通过", value: 2 }
      ],
      formData: {
        sourceDocType: "销售",
        sourceDocNo: "",
        putInStorageList: [],
      },
      // buttonselectlist: [{ name: "订单出库" }, { name: "自行出库" }],
      formDatalists: [
        {
          type: "input",
          porp: "outboundOrderNo",
          selectValue: "outboundOrderNo", // input Select Checkbox TimePicker
          typeObj: {},
          name: "出库单号",
          required: true
        },
        {
          type: "Select",
          porp: "outboundOrderType",
          selectValue: "outboundOrderType", // input Select Checkbox TimePicker
          typeObj: {
            list: [
            { name: "销售出库", value: 0 },
              { name: "自行出库", value: 1 },
            ]
          },
          name: "出库形式",
          required: true
        },
        // {
        //   type: "Select",
        //   porp: "warehousingType",
        //   selectValue: "warehousingType",
        //   typeObj: {
        //     list: [
        //       { name: "成品", value: "成品" },
        //       { name: "半成品", value: "半成品" },
        //       { name: "原材料", value: "原材料" }
        //     ]
        //   },
        //   name: "出库类型",
        //   required: true
        // },
     /*    {
          type: "Select",
          porp: "stordocName",
          selectValue: "stordocNo", // input Select Checkbox TimePicker
          typeObj: {},
          name: "仓库",
          required: true
        }, */
        {
          type: "Select",
          porp: "materialName",
          selectValue: "materialNo", // input Select Checkbox TimePicker
          typeObj: {},
          name: "出库货名",
          required: true
        },
        // {
        //   type: "Select",
        //   porp: "batchNo",
        //   selectValue: "batchNo", // input Select Checkbox TimePicker
        //   typeObj: {},
        //   name: "批次号",
        //   required: true
        // },
        // {
        //   type: "input",
        //   porp: "lotNumber",
        //   selectValue: "lotNumber", // input Select Checkbox TimePicker
        //   typeObj: {},
        //   name: "批号",
        //   required: true
        // },
       /*  {
          type: "input", // input Select Checkbox TimePicker
          porp: "shouldSendNum",
          typeObj: {},
          name: "应出数量",
          required: true,
          notSearch: true
        },
        {
          type: "input", // input Select Checkbox TimePicker
          porp: "confirmQuantity",
          typeObj: {},
          name: "实出数量",
          required: true,
          notSearch: true
        },
        {
          type: "input", // input Select Checkbox TimePicker
          porp: "primaryQuantity",
          typeObj: {},
          name: "主数量",
          required: true,
          notSearch: true
        }, */
        // {
        //   type: "Select", // input Select Checkbox TimePicker
        //   porp: "castUnit",
        //   selectValue: "castUnitNo",
        //   typeObj: {},
        //   name: "单位",
        //   required: true,
        //   notSearch: true
        // },
        // {
        //   type: "Select", // input Select Checkbox TimePicker
        //   porp: "unit",
        //   selectValue: "unitNo",
        //   typeObj: {},
        //   name: "主单位",
        //   required: true,
        //   notSearch: true
        // },
       /*  {
          type: "input", // input Select Checkbox TimePicker
          porp: "exchangeRate",
          typeObj: {},
          name: "换算率",
          required: true
        },
        {
          type: "input", // input Select Checkbox TimePicker
          porp: "price",
          typeObj: {},
          name: "单价/元",
          required: true
        },
        {
          type: "input", // input Select Checkbox TimePicker
          porp: "totalPrice",
          typeObj: {},
          name: "总金额/元",
          required: true
        }, */

        {
          type: "date", // input Select Checkbox TimePicker
          porp: "outTime",
          typeObj: {},
          name: "出库日期",
          required: true
        },
        // {
        //   type: "input", // input Select Checkbox TimePicker
        //   porp: "weight",
        //   typeObj: {},
        //   name: "重量/kg",
        //   required: true
        // },
        // {
        //   type: "input", // input Select Checkbox TimePicker
        //   porp: "volume",
        //   typeObj: {},
        //   name: "体积/L",
        //   required: true
        // },
        // {
        //   type: "input", // input Select Checkbox TimePicker
        //   porp: "packNum",
        //   typeObj: {},
        //   name: "件数",
        //   required: true
        // },
/*         {
          type: "TimePicker", // input Select Checkbox TimePicker
          porp: "produceDate",
          typeObj: {},
          name: "生产日期",
          required: true
        },
        {
          type: "TimePicker", // input Select Checkbox TimePicker
          porp: "expirationDate",
          typeObj: {},
          name: "失效日期",
          required: true
        } */
        // {
        //   type: "Select",
        //   porp: "forderStatus",
        //   selectValue: "forderStatus", // input Select Checkbox TimePicker
        //   typeObj: {
        //     list: [
        //       { name: '未审核', value: 0 },
        //       { name: '审核通过', value: 1 },
        //       { name: '审核未通过', value: 2 }
        //     ]
        //   },
        //   name: "单据状态",
        //   required: true
        // }
      ],
      rules: {}
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {
    dialogFormVisible(v) {
      if (v) {
        this.$nextTick(()=>{
          this.$refs.formData.clearValidate()
        })
      }
    },
    formData: {
      deep: true,
      handler(val) {
        if (val.putInStorageList) {
          val.putInStorageList.forEach((item, index) => {
            if (item.exchangeRate && item.arriveNum) {
              this.formData.putInStorageList[index].primaryQuantity =
                item.exchangeRate * item.arriveNum;
            }
            // if (item.price && item.arriveNum) {
            //   this.formData.putInStorageList[index].totalPrice = item.price * item.arriveNum
            // }
          });
        }
      }

    }
  },

  created() {
    let list = []
    this.formDatalists.map(el => {
      let obj = {
        prop: el.porp, label: el.name, minWidth: '140px'
      }
      if (['outboundOrderType', 'shouldSendNum', 'confirmQuantity', 'primaryQuantity'].includes(el.porp)) {
        obj.slotName = el.porp
      }
      list.push(obj)
    })
    list.push({ prop: 'name', label: '申请人', slotName: 'name', width: '180' })
     list.push({ prop: 'materialInfo', label: '查看详情', slotName: 'materialInfo', width: '180' })
    list.push({ prop: 'operation', label: '操作', slotName: 'operation', width: '180' })

    this.tableColumn = list
    this.getMaterialList();
    // this.getSupplierList();
    this.getstordocList();
    this.getUnitList();
    this.getOederList();
    this.getPersonList();
    this.getSourceDocNoList();
    this.toAdd = this.$route.params;
  },
  mounted() {},
  methods: {
    getType (value) {
      let val = ''
      switch (value) {
        case 0:
          val = '销售出库'
          break;
        case 1:
          val = '自行出库'
          break;
        case 2:
          val = '领料出库'
          break;
        case 3:
          val = '调拨出库'
          break;
        case 4:
          val = '委托加工出库'
          break;
        default:
          val = ''
          break;
      }
      return val
    },
    arrivalToputin() {
      deliveryDetailApi
        .queryListByDeliveryNo(this.toAdd.arriveOrderNo)
        .then(res => {
          if (res.code === 1) {
            this.$set(this.formData, "sourceDocType", "销售");
            this.formData.sourceDocNo = res.data[0].saleOrderNo;
            this.$set(this.formData, "outGoodsList", []);
            this.outGoodsList = res.data;
            this.$set(this.formData, "outGoodsList", res.data);
            this.chooseGoods(res.data);
          }
        });
      this.outboundOrderType = 0
      this.outboundOrderNo = 0
      this.nowChanceStau = "add";
      this.titleText = "添加出库";
      this.addActive = false;
      this.delActive = false;
      this.dialogFormVisible = true;
    },
    // 判断货存量
    getMainQuantity(e, index, i) {
      this.formData.putInStorageList[index].lineList[i].primaryQuantity =
        e * this.formData.putInStorageList[index].lineList[i].exchangeRate;
      if (
        this.formData.putInStorageList[index].lineList[i].primaryQuantity >
        this.formData.putInStorageList[index].lineList[i].nowQuantity
      ) {
        this.$message.warning("出货数量大于现存数量，请重新选择出货数量");
        this.formData.putInStorageList[index].lineList[i].confirmQuantity = "";
      }
      this.formDataChange(e)
    },
    // 获取源头单号
    getSourceDocNoList() {
      saleOrderApi.conditionQuery({ forderStatus: 1 }).then(res => {
        if (res.code === 1) {
          this.sourceDocNoList = res.data;
        }
      });
    },
    addLineDetail(index) {
      this.formData.putInStorageList[index].lineList.push({})
      this.formData = { ...this.formData }
    },
    delLineDetail(index, i) {
      if (this.formData.putInStorageList[index].lineList.length === 1) {
        return;
      } else {
        this.formData.putInStorageList[index].lineList.splice(i, 1);
        this.formData = { ...this.formData }
      }
    },
    // 添加一个出库单
    addOrderDetail() {
        if(this.nowChanceStau==='add'){
          this.formData.putInStorageList.push({
            lineList: [{}],
            outboundOrderType: this.outboundOrderType,
            lotNumber:this.lotNumber,
            warehousingType: "",
            stordocNo: "",
            materialNo: "",
            batchNo: "",
            primaryQuantity: "",
            unitNo: "",
            arriveNum: "",
            castUnitNo: "",
            exchangeRate: "",
            shouldSendNum: "",
            price: "",
            outTime:"",
            totalPrice: "",
            sourceDocType: "销售",
            sourceDocNo: "",
            associatedDocumentType: "销售明细",
            assassociatedDocumentNo: "",
            weight: "",
            volume: "",
            packNum: "",
            produceDate: "",
            expirationDate: "",
            forderStatus: 0,
            organizationNo: sessionStorage.organizationNo,
            key: Date.now(),
          });
        }else if(this.nowChanceStau==='auditing'){
          this.formData.putInStorageList.push({
            lineList: [{}],
            batchList: this.formData.putInStorageList[0].batchList,
            outboundOrderType: this.outboundOrderType,
            lotNumber:this.lotNumber,
            warehousingType: "",
            stordocNo: "",
            materialNo: this.formData.putInStorageList[0].materialNo,
            batchNo: "",
            primaryQuantity: "",
            unitNo: "",
            arriveNum: "",
            castUnitNo: "",
            exchangeRate: "",
            shouldSendNum: "",
            price: "",
            outTime:"",
            totalPrice: "",
            sourceDocType: "销售",
            sourceDocNo: "",
            associatedDocumentType: "销售明细",
            assassociatedDocumentNo: "",
            weight: "",
            volume: "",
            packNum: "",
            produceDate: "",
            expirationDate: "",
            forderStatus: 0,
            organizationNo: sessionStorage.organizationNo,
            key: Date.now(),
          });
        }
    },
    // 删除一个出库单
    delOrderDetail(index) {
      if (this.formData.putInStorageList.length === 1) {
        return;
      } else {
        this.formData.putInStorageList.splice(index, 1);
      }
    },
    // 页面切换
    nowselectbuttonindex(index) {
      this.forderStatus = index;
      this.currentPage = 1;
      this.search();
    },
    // 获取所有物料
    getMaterialList() {
      materialApi.getqueryList({}).then(res => {
        if (res.code === 1) {
          this.materialList = res.data;
          this.$set(this.formDatalists[3], "typeObj", {
            list: res.data,
            listName: ["materialName", "materialNo"]
          });
          this.setOptions(this.formConfig, 'materialNo', res.data)
        }
      });
    },
    // 获取人员列表
    getPersonList() {
      personApi.getStaffListByCondition().then(res => {
        if (res.code === 1) {
          this.personList = res.data;
          let list = [];
          res.data.forEach(item => {
            list.push({
              name: item.person.name,
              value: item.personNo
            });
          });
          this.formDatalists.forEach((item, index) => {
            if (item.prop === "receiverName") {
              this.$set(this.formDatalists[index].typeObj, "list", list);
            }
          });
        }
      });
    },
    // 获取所有销售订单
    getOederList() {
      saleOrderApi
        .conditionQuery({ completeStatus: false, forderStatus: 1 })
        .then(res => {
          if (res.code === 1) {
            let list = [];
            res.data.forEach(item => {
              list.push({
                name: item.orderNo,
                value: item.orderNo
              });
            });
            this.formDatalists.forEach((item, index) => {
              if (item.prop === "orderNo") {
                this.$set(this.formDatalists[index].typeObj, "list", list);
              }
            });
            this.formDatalists.forEach((item, index) => {
              if (item.prop === "personName") {
                this.$set(this.formDatalists[index].typeObj, "list", list);
              }
            });
          }
        });
    },
    // 获取仓库
    getstordocList() {
      warehouseApi.conditionQuery({}).then(res => {
        if (res.code === 1) {
          this.stordocList = res.data;
          this.formDatalists.forEach((item, index) => {
            if (item.prop === "stordocName") {
              this.$set(this.formDatalists[index], "typeObj", {
                list: res.data,
                listName: ["stordocName", "stordocNo"]
              });
            }
          });
          this.setOptions(this.formConfig, 'stordocNo', res.data)
        }
      });
    },
    // 获取单位列表X
    getUnitList() {
      unitApi.getPlantingUnitListByCondition({}).then(res => {
        if (res.code === 1) this.unitList = res.data;
      });
    },
    formDataChange() {
      this.formData = { ...this.formData }
    },
    // 选择现存量来填充其他属性
    batchObjChange(event, index, i) {
      const batchObj = this.formData.putInStorageList[index].lineList[i];
      this.$set(batchObj, 'batchNo', event.batchNo);
      this.$set(batchObj, 'stordocNo', event.stordocNo);
      this.$set(batchObj, 'lotNumber', event?.batchFile?.lotNumber);
      this.$set(batchObj, 'castUnitNo', event.castUnitNo);
      this.$set(batchObj, 'unitNo', event.unitNo);
      this.$set(batchObj, 'exchangeRate', event.changerate);
      this.$set(batchObj, 'nowQuantity', event.onHandQuantity);
      this.$set(batchObj, 'expirationDate', event?.batchFile?.expirationDate ?? '');
      this.$set(batchObj, 'produceDate', event?.batchFile?.produceDate ?? '');
      this.formData = { ...this.formData }
    },

    timeEvent(event, prop) {
      if (prop === "arriveTime") {
        this.formData.putInStorageList.forEach((item, index) => {
          this.$set(this.formData.putInStorageList[index], "arriveTime", event);
        });
      }
    },
    // 获取单个商品
    getGoods(event, index) {
      this.formData.putInStorageList[index].batchObj = {};
      handQuantityApi.conditionQuery({ materialNo: event }).then(res => {
        if (res.code === 1) {
          let batchList = res.data;
          this.$set(this.formData.putInStorageList[index], 'batchList', batchList)
          if(this.nowChanceStau!=='add' ){
            const currentBatchObj = this.formData.putInStorageList[index].batchObj;
            const matchedBatch = batchList.find(batch => batch.batchNo ===  this.batchNo);
            if(matchedBatch) {
              this.$set(this.formData.putInStorageList[index], 'batchObj', matchedBatch);
              this.$set(this.formData.putInStorageList[index], 'nowQuantity', matchedBatch.onHandQuantity);
              this.$set(this.formData.putInStorageList[index], 'produceDate', matchedBatch.batchFile?.produceDate);
              this.$set(this.formData.putInStorageList[index], 'expirationDate', matchedBatch.batchFile?.expirationDate);
            }
          }
        }
      });
    },

    // 选择出货商品
    chooseGoods(e) {
      this.$set(this.formData, "putInStorageList", e);
      this.formData.putInStorageList[0].outboundOrderNo = this.outboundOrderNo;
      this.formData.putInStorageList.forEach((item, index) => {
        this.formData.putInStorageList[
          index
        ].sourceDocType = this.formData.sourceDocType;
        this.formData.putInStorageList[
          index
        ].sourceDocNo = this.formData.sourceDocNo;
        this.formData.putInStorageList[index].associatedDocumentType =
          this.formData.sourceDocType + "明细";
        this.formData.putInStorageList[index].associatedDocumentNo =
          item.orderDetailNo;
        this.$set(
          this.formData.putInStorageList[index],
          "shouldSendNum", item.shouldSendNum
        );
        this.$set(this.formData.putInStorageList[index], "forderStatus", 0);
        this.formData.putInStorageList[index].key = Date.now();
        this.formData.putInStorageList[
          index
        ].outboundOrderType = this.outboundOrderType;
      });
    },
    // 获取订单详细列表
    getOrderDetailList(e) {
      saleOrderDetailApi.queryListBySaleOrderNo(e).then(res => {
        if (res.code === 1) {
          this.$set(this.formData, "outGoodsList", []);
          this.outGoodsList = res.data;
          this.$set(this.formData, "outGoodsList", [this.outGoodsList[0]]);
          this.chooseGoods([this.outGoodsList[0]]);
        }

      });
    },
    getTableDataList() {
      this.loading = true;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        organizationNo: sessionStorage.organizationNo,
        breedTypeNo: sessionStorage.breedTypeNo,
        entity: {
          forderStatus: this.forderStatus,
          ...this.searchlist,
            startTime: this.searchlist.outTime && this.searchlist.outTime[0],
          endTime: this.searchlist.outTime && this.searchlist.outTime[1],
        }
      };
      delete params.entity.outTime;
      outStorage.pageQuery(params).then(res => {
        this.loading = false;
        let data = res.data;
        if (data) {
          this.totalSize = data.totalElements;
          const formattedData = data.content.map(item => {
            if (item.outboundOrderList && item.outboundOrderList.length > 0) {
              item.materialName = item.outboundOrderList.map(entry => entry.materialName).join(' , ');
            } else {
              item.materialName = '';
            }
            return item;
          });
          this.tableData = formattedData;
          this.addblankmet();
          this.resetActionBar();
          if (this.toAdd.isTo === "toAdd") {
            this.arrivalToputin();
          }
          this.toAdd = {};
        }
      });
    },
    handleSelectionChange(list) {
      this.selectedStaffList = [];
      this.selectedStaffList = list.map(item => item.outboundOrderNo);
      if (this.selectedStaffList.length > 0) this.delActive = true;
      else this.delActive = false;
    },
    delmessage() {
      outStorage
        .numberBatchDel({ noList: this.selectedStaffList })
        .then(res => {
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.search();
          } else {
            this.$message.warning(res.msg || "删除失败");
          }
        });
    },
    confirm() {
        if (!this.formData.reason) {
          this.$message.error('请填写驳回原因');
          return;
        }
        this.formData.putInStorageList.reason = this.formData.reason;
        this.formData.putInStorageList = this.formData.putInStorageList.map(item => {
                return { ...item, forderStatus: 2 ,reason:this.formData.reason};
              });
        let param = this.formData.putInStorageList.filter(el => { return el.outboundOrderNo })
        outStorage.reject(param).then(res => {
          if (res.code === 1) {
            this.$message.success(res.msg || "驳回成功！");
            this.dialogFormVisible = false;
            this.search();
            this.$refs[formData].resetFields();
          } else {
            this.$message.error(res.msg || "驳回失败！");
          }
        });
      },

    cancel(){
      this.dialogFormVisible = false;
      this.formData.reason=''
    },
    handleDelete(val) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass"
      })
        .then(() => {
          outStorage.numberDel(val).then(res => {
            if (res.code === 1) {
              this.$message.success(res.msg);
              this.search();
            } else {
              this.$message.warning(res.msg || "删除失败");
            }
          });
        })
        .catch(() => {});
    },
    changeAddWays(e) {
      this.outboundOrderType = e;
      if (this.outboundOrderType === 0) {
        this.formData = {
          sourceDocNo: "",
          sourceDocType: "销售",
          putInStorageList: []
        };
      }
      if (this.outboundOrderType === 1) {
        this.formData = {
          putInStorageList: [
            {
              lineList: [{}],
              outboundOrderType: this.outboundOrderType,
              warehousingType: "",
              stordocNo: "",
              materialNo: "",
              batchNo: "",
              lotNumber: "",
              primaryQuantity: "",
              unitNo: "",
              arriveNum: "",
              castUnitNo: "",
              exchangeRate: "",
              shouldSendNum: "",
              price: "",
              totalPrice: "",
              outTime: "",
              weight: "",
              volume: "",
              packNum: "",
              produceDate: "",
              expirationDate: "",
              forderStatus: 0,
              organizationNo: sessionStorage.organizationNo,
              key: Date.now()
            }
          ]
        };
      }
      // 获取入库订单编号
      nowpagereqquery.addcode("OUTBOUND_ORDER").then(res => {
        this.outboundOrderNo = res.data;
        this.typeFlag === 1 && (this.formData.putInStorageList[0].outboundOrderNo = res.data)
      });
    },
    add() {
      this.formData.putInStorageList = [];
      this.arrivalGoodsList = [];
      if (this.outboundOrderType === 0) {
        this.formData = {
          sourceDocNo: "",
          sourceDocType: "销售",
          putInStorageList: []
        };
      }
      if (this.outboundOrderType === 1) {
        this.formData = {
          putInStorageList: [
            {
              lineList: [{}],
              outboundOrderType: this.outboundOrderType,
              warehousingType: "",
              stordocNo: "",
              materialNo: "",
              batchNo: "",
              lotNumber: "",
              primaryQuantity: "",
              unitNo: "",
              arriveNum: "",
              castUnitNo: "",
              exchangeRate: "",
              shouldSendNum: "",
              price: "",
              totalPrice: "",
              outTime: "",
              weight: "",
              volume: "",
              packNum: "",
              produceDate: "",
              expirationDate: "",
              forderStatus: 0,
              organizationNo: sessionStorage.organizationNo,
              key: Date.now()
            }
          ]
        };
      }
      // 获取入库订单编号
      nowpagereqquery.addcode("OUTBOUND_ORDER").then(res => {
        this.outboundOrderNo = res.data;
      });
      this.outboundOrderType = 0
      this.outboundOrderNo = 0
      this.nowChanceStau = "add";
      this.titleText = "添加出库";
      this.addActive = false;
      this.delActive = false;
      this.dialogFormVisible = true;
    },
    edit(row, e) {
        this.outboundOrderType = row.outboundOrderType;
        this.outboundOrderNo = row.outboundOrderNo;
        this.batchNo=row.batchNo
        this.$set(this.formData, "putInStorageList", [
          { key: Date.now(), ...row }
        ]);
        this.$set(this.formData,"outboundOrderNo",row.outboundOrderNo)
        this.$set(this.formData,"outTime",row.outTime)
        this.$set(this.formData,"reason",row.reason)
        let outboundOrderList = [
          ...row.outboundOrderList
        ]
        outboundOrderList.map(el => {
          el.lineList = [{...el}]
        })
        this.$set(this.formData,"putInStorageList", outboundOrderList)
        this.nowChanceStau = e;
        if (e !== "add" && row.outboundOrderType != 0) {
          this.formData.putInStorageList.forEach((detail, index) => {
            this.getGoods(detail.materialNo, index);
          });
        }
        let a = e === "check" ? "出库详情" : e === "material" ? "物料详情" : e === "auditing" ? "审核" : e === "reject" ? "驳回原因" : "修改入库";
        this.titleText = a;
        this.dialogFormVisible = true;
        this.addActive = true;
        this.delActive = false;
      },

    kookInfo(e) {
      this.formData = {};
      deliveryDetailApi.queryListByDeliveryNo(e).then(res => {
        if (res.code === 1) {
          this.$set(this.formData, "putInStorageList", res.data);
        }
      });
      this.nowChanceStau = "kookInfo";
      this.titleText = "查看出货明细";
      this.dialogFormVisible = true;
      this.addActive = true;
      this.delActive = false;
    },
    addDetail(e, index) {
      let validateFieldList = [];
      this.$refs["formData"].validateField(
        [
          "putInStorageList." + index + ".materialNo",
          "putInStorageList." + index + ".confirmQuantity",
          "putInStorageList." + index + ".castUnitNo",
          "putInStorageList." + index + ".unitNo",
          "putInStorageList." + index + ".exchangeRate",
          "putInStorageList." + index + ".primaryQuantity",
          "putInStorageList." + index + ".price",
          "putInStorageList." + index + ".packNum",
          "putInStorageList." + index + ".totalPrice",
          "putInStorageList." + index + ".address"
        ],
        valid => {
          if (!valid) {
            validateFieldList.push(valid);

            // 因为我这里总共校验了三个字段,所有最终三个字段都校验成功之后,数组中会有三个""
            if (
              validateFieldList.length === 10 &&
              validateFieldList.every(item => item === "")
            ) {
              saleOrderDetailApi.add(e).then(res => {
                if (res.code === 1) {
                  this.$message.success(res.msg);
                  saleOrderDetailApi.numberQuery(e.orderNo).then(res => {
                    this.$set(this.formData, "putInStorageList", res.data);
                  });
                } else {
                  this.$message.warning(res.msg || "添加失败");
                }
              });
            }
            // 校验不通过走这里
            return;
          } else {
            return false;
          }
        }
      );
    },
    editDetail(e) {
      this.$confirm("确定修改该条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass"
      })
        .then(() => {
          saleOrderDetailApi.edit(e).then(res => {
            if (res.code === 1) {
              this.$message.success(res.msg);
            } else {
              this.$message.warning(res.msg || "修改失败");
            }
          });
        })
        .catch(() => {});
    },
    delDetial(e, index) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass"
      })
        .then(() => {
          saleOrderDetailApi.numberQuery(e.orderNo).then(res => {
            if (res.data.length <= 1) {
              this.$message.warning("已是最后一条数据禁止删除");
            } else {
              saleOrderDetailApi.numberDel(e.orderDetailNo).then(res => {
                if (res.code === 1) {
                  this.$message.success(res.msg);
                  this.formData.putInStorageList.splice(index, 1);
                } else {
                  this.$message.warning(res.msg || "删除失败");
                }
              });
            }
          });
        })
        .catch(() => {});
    },
    save(formData) {
      this.$refs[formData].validate(valid => {
        if (valid) {
          // 添加仓库名称
          this.formData.putInStorageList.forEach((item, index) => {
            if (item.lineList[0].stordocNo) {
              this.stordocList.forEach(item1 => {
                if (item1.stordocNo === item.lineList[0].stordocNo) {
                  this.formData.putInStorageList[index].stordocName =
                    item1.stordocName;
                }
              });
            }
          });
          let params = []
          this.formData.putInStorageList.map(el => {
            console.log(el.shouldSendNum)
            let co = 0
            el.lineList.map((ele, i) => {
              co += ele.primaryQuantity || 0
              let obj = {
                ...el, ...ele
              }
              i != 0 && obj.outboundOrderId && delete obj.outboundOrderId
              params.push(obj)
            })
            if (co != el.shouldSendNum) {
              this.$message.warning("主数量不等于应出数量");
              return
            }
          })
          if (this.nowChanceStau === "add") {
            const name = sessionStorage.getItem('account') ;
            params = params.map(item => {
              return { ...item, name: name };
            });
            outStorage.batchAdd(params).then(res => {
              if (res.code === 1) {
                this.$message.success(res.msg || "新增成功！");
                this.dialogFormVisible = false;
                this.search();
                this.$refs[formData].resetFields();
              } else {
                this.$message.error(res.msg || "新增失败！");
              }
            });
          } else if (this.nowChanceStau === "check" || this.nowChanceStau === "auditing") {
            params = params.map(item => {
              return { ...item, forderStatus: 1 };
            });
            outStorage.check(params).then(res => {
              if (res.code === 1) {
                this.$message.success(res.msg || "审核成功！");
                this.dialogFormVisible = false;
                this.search();
                this.$refs[formData].resetFields();
              } else {
                this.$message.error(res.msg || "审核失败！");
              }
            });
          }
        } else {
          return false;
        }
      });
    }
  }
};
</script>
<style scoped lang="scss">
@import "~@/styles/variables.scss";
::v-deep
  .el-dialog__wrapper
  .el-dialog
  .el-dialog__body
  .el-form
  .el-form-item
  .el-form-item__label {
  min-width: 140px;
}
.xunhuan {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-top: 30px;
  &.first {
    margin-top: 0;
  }
  .goods {
    width: 100%;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 20px;
    text-align: left;
    padding-left: 140px;
    // margin-top: 20px;
  }
  .editBox {
    z-index: 100;
    position: absolute;
    right: 0px;
    bottom: -30px;
  }
}
.addone {
  margin-left: 140px;
}
.zhu {
  display: flex;
  ::v-deep .el-input__inner {
    background-color: rgb(241, 239, 239) !important;
  }
}
.numberUnit {
  display: flex;
  .one {
    width: 65%;
  }
  .two {
    width: 35%;
  }
}
.block {
  display: block;
  width: 100%;
  position: relative;
  .addone {
    position: absolute;
    bottom: -30px;
  }
}
.line-box {
  position: relative;
  width: 100%;
  margin-bottom: 40px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  &.margin {
    margin-bottom: 0;
  }
}
</style>
